var LOCALURL = "http://localhost:8080";
function myAjax(url,type,data,dataType) {
    let result = null;
    $.ajax({
        url: LOCALURL + url,
        type: type,
        async: false,//必须写该句，才能同步处理
        data: data,
        dataType: dataType,
        xhrFields: {
            withCredentials: true //默认情况下，标准的跨域请求是不会发送cookie的
        },
        success: function (data) {
            console.log(data);
            result = data;
        },
        error: function (data) {
            console.log(data);
            result = data;
        }
    });
    return result;
}
function uploadAjax(url,type,data,dataType) {
    let result = null;
    $.ajax({
        url: LOCALURL + url,
        type: type,
        data: data,
        dataType: dataType,
        async: false,//必须写该句，才能同步处理
        processData: false,
        contentType: false,
        xhrFields: {
            withCredentials: true //默认情况下，标准的跨域请求是不会发送cookie的
        },
        success: function (data) {
            result = data;
        },
        error: function (data) {
            result = data;
        }
    });
    return result;
}
function commonData() {
    let data = sessionStorage.getItem("commonData");
    if (data==""||data==null) {
        data = JSON.stringify(myAjax("/common/data", "post", '', 'json'));
        sessionStorage.setItem("commonData", data);
    }
    return data;
}

function productData(page, product_type) {
    let pageNum = 1;
    let productType = 0;
    if (page == null || page == '')
        page = pageNum;
    if (product_type == null || product_type == '')
        product_type = productType;
    let data = sessionStorage.getItem("productData");
    if (data==""||data==null) {
        data = JSON.stringify(myAjax('/product', 'post', {"product_type": product_type, "page": page}, 'json'));
        sessionStorage.setItem("productData", data);
    }
    return data;
}